<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2023/6/13
 * Time: 下午5:16
 */

namespace app\test\controller;

use app\common\lib\astrolog\Astrolog;
use app\common\model\Recode;
use think\Controller;

/**
 * Class Record
 * @package app\test\controller
 */
class Record extends Controller
{
    public function makeText()
    {
        $recordList = (new Recode())->where(['uid' => 2])->order('id asc')->limit(100)->select();
        // 行星点
        $planet_name = [
            0 => '太阳', 1 => '月亮', 2 => '水星', 3 => '金星', 4 => '火星',
            5 => '木星', 6 => '土星', 7 => '天王', 8 => '海王', 9 => '冥王',
            10 => '凯龙', 11 => '莉莉斯', 12 => '北交', 13 => '婚神', 14 => '福点',
            15 => '宿命点', 16 => '南交',
            17 => '上升', 18 => '天底', 19 => '下降', 20 => '天顶',
        ];
        // 12星座
        $sign_name = [
            1 => '白羊', 2 => '金牛', 3 => '双子', 4 => '巨蟹',
            5 => '狮子', 6 => '处女', 7 => '天秤', 8 => '天蝎',
            9 => '射手', 10 => '摩羯', 11 => '水瓶', 12 => '双鱼'
        ];

        $phase_name = [
//            0 => '合相',
//            60 => '正相位',
//            90 => '负相位',
//            120 => '正相位',
//            180 => '负相位',
            0 => '合相',
            60 => '六分相',
            90 => '刑相',
            120 => '三分相',
            180 => '冲相',
        ];
        // 获取用户本命盘数据
        $userSetting['natal'] = json_decode('{"planet":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]],"phase":{"0":[1,8],"60":[1,6],"90":[1,7],"120":[1,7],"180":[1,7],"45":[0,0],"135":[0,0],"30":[0,0],"150":[0,0],"72":[0,0],"144":[0,0]},"arabic":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"h_sys":"p","ecliptic":0,"firdaria":"default","profection_push_direction":0,"decanates":0,"bound_type":"default","ayanamsa":0}', true);
        $astro = Astrolog::getInstance()
            ->setExecPrefix(config('astrolog.prefix'))
            ->setIsAstrolabe(true)
            ->setUserSetting($userSetting)
            ->setVersion(2);
        $text = '文件更新时间：' . date('Y-m-d H:i:s') . PHP_EOL . PHP_EOL;
        foreach ($recordList as $record)
        {
            $natalData = $astro
                ->setRecode1($record)
                ->setGetDatas(['natal'])
                ->getAstroDatas()
                ->getDatas('natal');

            $text .= '行星落座：';
            foreach ($natalData['planets'] as $planet)
            {
                $text .= $planet_name[$planet['id']] . $sign_name[$planet['in_sign_id']] . ' ';
            }
            $text .= PHP_EOL . '行星落宫：';
            foreach ($natalData['planets'] as $planet)
            {
                if ($planet['id'] < 17)
                {
                    $text .= $planet_name[$planet['id']] . $planet['in_house_id'] . '宫 ';
                }
            }
            $text .= PHP_EOL . '宫头星座：';
            foreach ($natalData['houses'] as $h => $house)
            {
                $text .= $h . '宫头' . $sign_name[$house['in_sign_id']] . ' ';
            }
            $text .= PHP_EOL . '宫主星：';
            foreach ($natalData['houses'] as $h => $house)
            {
                $text .= $h . '宫主' . $planet_name[$house['protect_id']] . ' '; // . '飞' . $house['protect_inhouse_id'] . '宫 ';
            }
            $text .= PHP_EOL . '相位：';
            foreach ($natalData['phase'] as $phase)
            {
                if ($phase['id1'] < $phase['id2'] && $phase['id1'] <= 5 && $phase['id2'] <= 10)
                {
                    $text .= $planet_name[$phase['id1']] . '和' . $planet_name[$phase['id2']] . $phase_name[$phase['phase_deg']] . ' ';
                }
            }
            $text .= PHP_EOL . '行星度数：';
            foreach ($natalData['planets'] as $planet)
            {
                if (in_array($planet['id'], [0, 1, 2, 3, 4, 17], true))
                {
                    $text .= $planet_name[$planet['id']] . $sign_name[$planet['in_sign_id']] . ((int)$planet['in_sign_deg_e']) . '度 ';
                }
            }
            $text .= PHP_EOL . PHP_EOL;
        }
        file_put_contents(ROOT_PATH . '档案数据.txt', $text);
    }
}
